<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    /**
     * 首页
     */
    //前置操作方法
    public function _before_index(){
        $user = is_login();
        if(!$user){
            $this->redirect('Login/index');
        }
    }
    public function index() {
        $uid            = is_login();
        if($uid){
            //公告提醒数字
            $M_notice       = M('notice');
            $M_notice_b     = M('notice_browse');
            $info = $M_notice_b->where('uid = '.$uid)->find();
            $list = $M_notice->count();
            if($info){
                $notice_num = $list - $info['num'];
            }else{
                $notice_num = $list;
            }
            //end
            //公告列表
            $noticelist = $this->noticelist();
            //end
            //新闻
            $M_article      = M('article');
            $article        = $M_article->order('addtime desc')->limit('0,3')->select();
            //继续教育
            $M_learn        = M('learn');
            $learn          = $M_learn->order('addtime desc')->limit('0,5')->select();
            //end
            //轮播图
            $adlist = $this->adlist();
            //end
            //医联体简介
            $aboutlist = $this->aboutlist();
            //end
            $this->assign(array(
                'noticelist' => $noticelist,
                'adlist'    => $adlist,
                'article'   => $article,
                'learn'     => $learn,
                'aboutlist' => $aboutlist,
                'notice_num'=> $notice_num
            ));
            $this->display();
        }else{
            $this->redirect('Login/index');
        }
    }

    /**
     * 首页轮播图
     */
    public function adlist() {
        $M_list     = M('ad');
        $list       = $M_list->order('addtime desc')->select();
        //print_r($list);
        return $list;
    }
    /**
     * 首页新闻列表
     */
    public function newslist() {
        $M_list     = M('article');
        $list       = $M_list->field('id,title,addtime')->select();
        /*foreach ($list as $key => $v){
            $list[$key]['addtime'] = date('m/d',strtotime($v['addtime']));
        }*/
        //print_r($list);
        return $list;
    }
    /**
     * 首页通告列表
     */
    public function noticelist() {
        $M_list     = M('notice');
        $list       = $M_list->field('id,title,addtime')->order('addtime desc')->select();
        foreach ($list as $key => $v){
            $list[$key]['addtime'] = date('m/d',strtotime($v['addtime']));
        }
        return $list;
    }
    /**
     * 首页继续教育列表
     */
    public function learnlist() {
        $M_list     = M('learn');
        $list       = $M_list->field('id,title,addtime')->order('addtime desc')->select();
        foreach ($list as $key => $v){
            $list[$key]['addtime'] = date('m/d',strtotime($v['addtime']));
        }
        //print_r($list);
        return $list;
    }
    /**
     * 首页医联体简介
     */
    public function aboutlist() {
        $M_list     = M('about');
        $list       = $M_list->find();
        return $list;
    }
    /**
     * 首页医联体简介详情
     */
    public function aboutdetail() {
        $info = $this->aboutlist();
        $this->assign('info',$info);
        $this->display();
    }
    public function aaa(){
        echo count('abcd');
    }
}